package jmine.tec.web.wicket.pages.form;

import bancosys.tec.exception.LocalizedMessageHolder;
import bancosys.tec.exception.MessageCreator;
import bancosys.tec.exception.MessageCreatorHelper;

/**
 * Classe que armazena as constantes referentes as mensagens internacionalizadas.
 * 
 * @author Rafael Volpato
 * @date Aug 2, 2011
 */
public enum WebFormPagesMessages implements MessageCreator {

    LABEL_BUTTON_SEARCH(0, "jmine.tec.web.wicket.button.search"),

    LABEL_BUTTON_NEW(0, "jmine.tec.web.wicket.button.new"),

    LABEL_BUTTON_BACK(0, "jmine.tec.web.wicket.button.back"),

    LABEL_SEARCH_RESULT(0, "jmine.tec.web.wicket.form.label.search.result"),

    LABEL_SEARCH_TITLE(1, "jmine.tec.web.wicket.form.label.search.title"),

    LABEL_FORM_TITLE(1, "jmine.tec.web.wicket.form.label.title"),

    INFO_ENTITY_SAVE_SUCCESS(0, "jmine.tec.web.wicket.form.info.entity.save.success"),

    INFO_ENTITY_DELETE_SUCCESS(0, "jmine.tec.web.wicket.form.info.entity.delete.success"),

    ERROR_CANNOT_FIND_ENTITY_TO_DELETE(2, "jmine.tec.web.wicket.form.error.cannot.find.entity.to.delete"),

    ERROR_CANNOT_FIND_ENTITY_TO_EDIT(2, "jmine.tec.web.wicket.form.error.cannot.find.entity.to.edit"),

    ERROR_CANNOT_FIND_ENTITY_TO_VIEW(2, "jmine.tec.web.wicket.form.error.cannot.find.entity.to.view"),

    ERROR_EXECUTION_NO_ENTITY_SELECTED(0, "jmine.tec.web.wicket.button.execution.error.noentityselected"),

    ERROR_EXECUTION_SINGLE_FAILED(0, "jmine.tec.web.wicket.button.execution.error.single"),

    ERROR_EXECUTION_MULTIPLE_FAILED(1, "jmine.tec.web.wicket.button.execution.error.multiple"),

    INFO_EXECUTION_SINGLE_SUCCESS(0, "jmine.tec.web.wicket.button.execution.success.single"),

    INFO_EXECUTION_MULTIPLE_SUCCESS(1, "jmine.tec.web.wicket.button.execution.success.multiple"),

    TIMEOUT_MESSAGE(0, "jmine.tec.web.wicket.pages.main.timeout.message"),

    ERROR_ON_FORM_VALIDATION(1, "jmine.tec.web.wicket.pages.form.validation");

    public static final String DEFAULT_BUNDLE = "jmine-tec-web-wicket-messages";

    private final String bundle;

    private final String key;

    private final int nargs;

    /**
     * Construtor
     * 
     * @param nargs nargs
     * @param key key
     */
    private WebFormPagesMessages(int nargs, String key) {
        this(DEFAULT_BUNDLE, key, nargs);
    }

    /**
     * Construtor
     * 
     * @param bundle bundle
     * @param key key
     * @param nargs nargs
     */
    private WebFormPagesMessages(String bundle, String key, int nargs) {
        this.bundle = bundle;
        this.key = key;
        this.nargs = nargs;
    }

    /**
     * Cria um message holder de acordo com os argumentos
     * 
     * @param arguments arguments
     * @return message holder
     */
    public LocalizedMessageHolder create(Object... arguments) {
        return MessageCreatorHelper.create(this.bundle, this.key, this.nargs, arguments);
    }

    /**
     * {@inheritDoc}
     */
    public int getExpectedArguments() {
        return this.nargs;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "MessageCreator: bundle=" + this.bundle + " key=" + this.key;
    }
}
